package rs.dalao.syc.user.all.controller;/*
 *   @author:Casin
 *   @date:2023/8/13
 *   @code:
 */

import com.github.xiaoymin.knife4j.annotations.ApiOperationSupport;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.security.core.annotation.AuthenticationPrincipal;
import org.springframework.web.bind.annotation.*;
import rs.dalao.syc.common.pojo.authentication.CurrentPrincipal;
import rs.dalao.syc.common.pojo.vo.PageData;
import rs.dalao.syc.common.response.JsonResult;
import rs.dalao.syc.user.all.pojo.vo.MedicineOrderVO;
import rs.dalao.syc.user.all.service.IMedicineService;
import springfox.documentation.annotations.ApiIgnore;

import java.util.List;

@RestController
@RequestMapping("/user/medicine")
@Api(tags = "1. 我的药品订单")
@Slf4j
public class MedicineController {
    @Autowired
    private IMedicineService service;

    @GetMapping("/orderList")
    @ApiOperation("获取药品订单信息")
    @PreAuthorize("hasAuthority('/user/medicine/orderList')")
    @ApiOperationSupport(order = 400)
    @ApiImplicitParams({
            @ApiImplicitParam(name = "page", value = "页码", defaultValue = "2", dataType = "long")
    })
    public JsonResult getPatientList(@AuthenticationPrincipal @ApiIgnore CurrentPrincipal currentPrincipal,Integer page){
        log.debug("开始处理【查询用户列表】的请求，页码：{}", page);
        Integer pageNum = page == null ? 1 : page;
        Long userId = currentPrincipal.getId();
        PageData<MedicineOrderVO> pageData = service.getMedicineOrderByUserId(userId,pageNum);
        return JsonResult.ok(pageData);
    }
}
